<?php
include_once '../includes/common.php';
if($islogin2==1){}else sysmsg("您还未登录，请先登录",2,'./login.php',true);
$title = '邀请返利';
include_once './header.php';
if($conf['invite_rebate_open']!=1)showmsg('错误','授权平台未开放邀请返利功能！',2,'./');
$count=$DB->count("SELECT count(*) FROM authguao_invitelog WHERE uid='{$userrow['uid']}'");
$moneycount=$DB->count("SELECT sum(money) FROM authguao_invitelog WHERE uid='{$userrow['uid']}' AND prize=0");
$rs=$DB->query("SELECT * FROM authguao_invitelog) WHERE uid='{$userrow['uid']}' order by id desc");
$url=($_SERVER['SERVER_PORT']==443 ? 'https://' : 'http://').$_SERVER['HTTP_HOST'].'/?mod=buy&invitecode='.$userrow['invitecode'];
$urls=($_SERVER['SERVER_PORT']==443 ? 'https://' : 'http://').$_SERVER['HTTP_HOST'].'/user/reg.php?invitecode='.$userrow['invitecode'];
if($conf['fanghong_api']>0){
    $turl = fanghongdwz($url);
    $turls = fanghongdwz($urls);
    if(strpos($turl,'/')===false || strpos($turls,'/')===false){
        $turl = $url;
        $turls = $urls;
    }
}else{
    $turl = $url;
    $turls = $urls;
}
?>
<div class="row">
    <div class="col-sm-12">
        <!-- Profile -->
        <div class="card bg-white">
            <div class="card-body profile-user-box">
                <div class="row">
                    <div class="col-sm-8">
                        <div class="media">
                            <span class="float-left m-2 mr-4"><img src="//q4.qlogo.cn/headimg_dl?dst_uin=<?php echo $userrow['qq'];?>&spec=640" style="height: 100px;" alt="" class="rounded-circle img-thumbnail"></span>
                            <div class="media-body">
                                <h4 class="mt-1 mb-1"><?php echo qqname($userrow['qq']) ?></h4>
                                <p class="font-13"> <?php echo $conf['sitename'] ?> <span class="badge badge-success-lighten ml-2">已认证</span></p>
                                <ul class="mb-0 list-inline">
                                    <li class="list-inline-item mr-3">
                                        <h5 class="mb-1"><?php echo $count ?>人</h5>
                                        <p class="mb-0 font-13">累计邀请人数</p>
                                        <h5 class="mb-1"><?php echo $userrow['invite_lq'] ?>次</h5>
                                        <p class="mb-0 font-13">累计领取奖励</p>
                                    </li>
                                </ul>
                            </div> <!-- end media-body-->
                        </div>
                    </div> <!-- end col-->
                    <div class="col-sm-4">
                        <div class="text-center mt-sm-0 mt-3 text-sm-right">
                            <button type="button" class="btn btn-danger btn-rounded btn-code" data-clipboard-target="#btn_code"><i class="mdi mdi-account-edit mr-1"></i> 复制注册邀请链接</button><div></br></div>
                            <button type="button" class="btn btn-danger btn-rounded btn-code" data-clipboard-target="#btn_codes"><i class="mdi mdi-account-edit mr-1"></i> 复制购买邀请链接</button>
                            <p class="mt-3 font-16 text-success">每邀请1个真实用户奖励<?php echo $conf['invite_money'];?>元</br>每邀请1名游客在线购买成功，将提取支付金额的<?php echo $conf['invite_rebate_sq'];?>%作为奖励</p>
                        </div>
                    </div> <!-- end col-->
                </div> <!-- end row -->
            </div> <!-- end card-body/ profile-user-box-->
        </div><!--end profile/ card -->
    </div> <!-- end col-->
    <div class="col-xl-6">
        <div class="card text-white bg-danger overflow-hidden">
            <div class="card-body">
                <div class="toll-free-box text-center font-18 ">
                    <i class="layui-icon layui-icon-gift"></i> <span class="mr-1">专属注册推广链接</span><span id="btn_code"><?php echo $turl ?></span>
                </div>
            </div> <!-- end card-body-->
        </div> <!-- end card-->
        <div class="card text-white bg-danger overflow-hidden">
            <div class="card-body">
                <div class="toll-free-box text-center font-18 ">
                    <i class="layui-icon layui-icon-gift"></i> <span class="mr-1">专属购买推广链接</span><span id="btn_codes"><?php echo $turls ?></span>
                </div>
            </div> <!-- end card-body-->
        </div> <!-- end card-->
        <!-- Personal-Information -->
        <div class="card mt-4">
            <div class="card-body">
                <h4 class="header-title mt-0 mb-3">专属邀请返利图
                    <span class="badge badge-primary p-1" onclick="location.reload()" style="cursor: pointer">换种样式 [图片<?php $rand = rand(1, 13);echo $rand; ?>]</span>
                    <a href="./image/timg.php?id=<?php echo $rand;?>&url=<?php echo $turl;?>" target="_blank" class="badge badge-success p-1">保存注册推广图</a>
                    <a href="./image/timg.php?id=<?php echo $rand;?>&url=<?php echo $turls;?>" target="_blank" class="badge badge-success p-1">保存购买推广图</a>
                </h4>
                <ul class="nav nav-tabs nav-justified nav-bordered mb-3">
                    <li class="nav-item">
                        <a href="#inviteimg1" data-toggle="tab" aria-expanded="false" class="nav-link active">
                            注册邀请图片
                        </a>
                    </li>
                    <li class="nav-item">
                        <a href="#inviteimg2" data-toggle="tab" aria-expanded="false" class="nav-link">
                            购买邀请图片
                        </a>
                    </li>
                </ul>
                <div class="tab-content">
                    <div class="tab-pane show active" id="inviteimg1">
                        <img class="card-img-top" src="./image/timg.php?id=<?php echo $rand;?>&url=<?php echo $turl;?>" alt="注册推广图片">
                    </div>
                    <div class="tab-pane" id="inviteimg2">
                        <img class="card-img-top" src="./image/timg.php?id=<?php echo $rand;?>&url=<?php echo $turls;?>" alt="购买推广图片">
                    </div>
                </div>
            </div>
        </div>
        <!-- Personal-Information -->
    </div>
    <div class="col-xl-6">
        <div class="card">
            <div class="card-body">
                <h4 class="header-title mb-3">我的邀请</h4>
                <div class="slimscroll" style="min-height: 435px;">
                    <?php while($res = $DB->fetch($rs)) { ?>
                        <div class="media p-2 shadow-sm">
                            <img class="mr-3 rounded-circle" src="//q.qlogo.cn/headimg_dl?dst_uin=<?php echo $res['qq'];?>&spec=640" width="40" alt="Generic placeholder image">
                            <div class="media-body">
                                <h5 class="mt-0 mb-1 text-justify"><?php echo qqname($res['qq']) ?></h5>
                                <span class="font-13"><?php echo $res['creation_time'] ?>
                            </span>
                                <?php
                                if ($res['prize'] == 1) {
                                    echo '<a href="javascript:layer.msg(\'您已经在<font color=#03de01>' . $res['draw_time'] . '</font>领取了奖励点!\')" class="badge badge-primary-lighten">您已经领取奖励</a>';
                                } else {
                                    echo '<span class="badge badge-success-lighten" onclick="getprize('.$res['id'].')">点我领取邀请奖励</span>';
                                }
                                ?>
                            </div>
                            <a class="badge badge-warning ml-1 text-white mt-3">待领取：<?php echo round($moneycount,2) ?></a>
                        </div>
                    <?php } ?>
                </div>
            </div>
            <!-- end card-body -->
        </div>
        <!-- end card-->
    </div>
</div>
<script src="https://cdn.bootcss.com/clipboard.js/2.0.4/clipboard.js"></script>
<?php
include_once 'bottom.php';
?>
<script>
    var clipboard = new ClipboardJS('.btn-code');
    clipboard.on('success', function (e) {
        layer.msg("复制成功<br>快去分享给朋友一起来赚钱吧！", {icon: 6});
        e.clearSelection();
    });
    clipboard.on('error', function (e) {
        layer.msg('专属链接复制失败,请手动复制链接~', {icon: 5});
    });
    var clipboards = new ClipboardJS('.btn-codes');
    clipboards.on('success', function (e) {
        layer.msg("复制成功<br>快去分享给朋友一起来赚钱吧！", {icon: 6});
        e.clearSelection();
    });
    clipboards.on('error', function (e) {
        layer.msg('专属链接复制失败,请手动复制链接~', {icon: 5});
    });
</script>